package com.sharelords.demo.web.controller;

import com.sharelords.demo.common.result.ViewResult;
import com.sharelords.demo.web.request.ConditionReqParam;
import com.sharelords.demo.web.request.DemoTestSaveParam;
import com.sharelords.demo.web.request.DemoTestUpdateParam;
import com.sharelords.demo.web.service.DemoTestService;
import com.sharelords.demo.web.vo.DemoTestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @description: demo项目接口测试
 *
 * @author: 千古龙少
 * @time: 2019/11/19 22:47
 */
@RestController
@RequestMapping("/test")
public class DemoTestController {

    @Autowired
    private DemoTestService demoTestService;

    /**
     * 新增
     *
     * @Author: 千古龙少
     * @Time: 2019/12/8 16:18
     * @param param
     * @return com.sharelords.demo.common.result.ViewResult<java.lang.Integer>
     */
    @PostMapping("/save")
    public ViewResult<Integer> save(@Valid DemoTestSaveParam param) {
        return this.demoTestService.save(param);
    }

    /**
     * 更新
     *
     * @Author: 千古龙少
     * @Time: 2019/12/8 16:19
     * @param param
     * @return com.sharelords.demo.common.result.ViewResult<java.lang.Integer>
     */
    @PostMapping("/update")
    public ViewResult<Integer> update(@Valid DemoTestUpdateParam param) {
        return this.demoTestService.update(param);
    }

    /**
     * 删除
     *
     * @Author: 千古龙少
     * @Time: 2019/12/8 16:20
     * @param id
     * @return com.sharelords.demo.common.result.ViewResult<java.lang.Integer>
     */
    @PostMapping("/delete")
    public ViewResult<Integer> delete(@RequestParam("id") Long id) {
        return this.demoTestService.delete(id);
    }

    /**
     * 根据id获取详情
     *
     * @author: 千古龙少
     * @time: 2019/11/19 23:21
     * @param id
     * @return com.sharelords.demo.web.vo.DemoTestVo
     */
    @GetMapping("/detail")
    public ViewResult<DemoTestVo> getDetail(@RequestParam("id") Long id) {
        return this.demoTestService.getDetail(id);
    }

    /**
     * 根据姓名获取详情
     *
     * @Author: 千古龙少
     * @Time: 2019/11/24 21:00
     * @param name
     * @return com.sharelords.demo.common.result.ViewResult<com.sharelords.demo.web.vo.DemoTestVo>
     */
    @GetMapping("/detailByName")
    public ViewResult<DemoTestVo> getDetailByName(@RequestParam("name") String name) {
        return this.demoTestService.getDetailByName(name);
    }

    /**
     * 多条件分页查询
     *
     * @Author: 千古龙少
     * @Time: 2019/11/25 23:48
     * @param reqParam
     * @param pageNum
     * @param pageSize
     * @return com.sharelords.demo.common.result.ViewResult<java.util.List<com.sharelords.demo.web.vo.DemoTestVo>>
     */
    @GetMapping("/pageList")
    public ViewResult<List<DemoTestVo>> getPageList(ConditionReqParam reqParam
            , @RequestParam(name = "pageNum", required = false, defaultValue = "0") Integer pageNum
            , @RequestParam("pageSize") Integer pageSize) {
        return this.demoTestService.getPageListByConditions(reqParam, pageNum, pageSize);
    }

    /**
     * 多条件查询记录数
     *
     * @Author: 千古龙少
     * @Time: 2019/11/26 23:58
     * @param reqParam
     * @return com.sharelords.demo.common.result.ViewResult<java.lang.Integer>
     */
    @GetMapping("/count")
    public ViewResult<Integer> getCount(ConditionReqParam reqParam) {
        return this.demoTestService.getCount(reqParam);
    }

}
